package com.google.code.swingonfire.plotter;

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Path2D;

public class NEdgePolygonSketch implements Sketch
{

    private final Rectangle bounds;
    private final Path2D path;

    public NEdgePolygonSketch(int edges, double radius)
    {
        super();

        bounds =
            new Rectangle((int) Math.floor(-radius), (int) Math.floor(-radius),
                (int) (Math.ceil(radius) - Math.floor(-radius)), (int) (Math.ceil(radius) - Math.floor(-radius)));
        path = new Path2D.Float();
        path.moveTo(radius, 0);

        for (int i = 1; i < edges; i += 1)
        {
            double theta = ((2 * Math.PI) / edges) * i;
            double x = Math.cos(theta) * radius;
            double y = -Math.sin(theta) * radius;

            System.out.println(((theta / (2 * Math.PI)) * 180) + ", " + x + ", " + y);
            path.lineTo(x, y);
        }

        path.closePath();
    }

    @Override
    public Rectangle getBounds()
    {
        return bounds;
    }

    @Override
    public void draw(Graphics2D g)
    {
        g.fill(path);
    }

}
